package com.four.reimbursemanage.controller;


import com.four.reimbursemanage.common.bean.ResponseData;
import com.four.reimbursemanage.common.controller.BaseController;
import com.four.reimbursemanage.dao.DailyapplyMapper;
import com.four.reimbursemanage.entity.Dailyapply;
import com.four.reimbursemanage.service.IDailyapplyService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;


import java.util.Date;
import java.util.List;

/**
 * 日常报销申请Controller
 * 
 * @author lwy
 * @date 2024-09-18
 */
@RestController
@CrossOrigin
@RequestMapping("/dailyapply")
public class DailyapplyController extends BaseController
{
    @Autowired
    private IDailyapplyService dailyapplyService;

    @Autowired
    DailyapplyMapper dailyapplyMapper;

    /**
     * 查询日常报销申请列表
     */

    @GetMapping("/dailyapplyList")
    public ResponseData<Object> getDailyapply(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam(value = "writedate",required = false)@DateTimeFormat(pattern = "yyyy-MM-dd")Date writedate,
            @RequestParam(value = "department",required = false) String department,
            @RequestParam(value = "reason",required = false) String reason,
            @RequestParam(value = "money",required = false) String money,
            @RequestParam(value = "rill",required = false) String rill,
            @RequestParam(value = "state",required = false) Integer state
    ){

        return returnObject(dailyapplyService.getOnrePage(pageNum,pageSize, writedate, department, reason, money, rill, state));
    }




    /**
     * 获取日常报销申请详细信息
     */

    @GetMapping( "/{id}")
    public ResponseData<Object> getInfo(@PathVariable("id") Integer id)
    {
        Dailyapply dailyapply=dailyapplyService.selectDailyapplyById(id);
        return returnObject(dailyapply);
    }

    /**
     * 新增日常报销申请
     */

    @PostMapping("/add")
    public ResponseData<Boolean> add(Dailyapply dailyapply)
    {
        System.out.println(dailyapply);
        return returnBoolean(dailyapplyService.insertDailyapply(dailyapply));
    }

    /**
     * 修改日常报销申请
     */

    @PutMapping("/update")
    public ResponseData<Boolean> edit(@RequestBody Dailyapply dailyapply)
    {
        return returnBoolean(dailyapplyService.updateDailyapply(dailyapply));
    }

    //更新状态可撤销
    @PutMapping("/updateC")
    public  ResponseData<Boolean> updateS(@RequestBody Dailyapply dailyapply){
        return returnBoolean(dailyapplyService.updateC(dailyapply));
    }

    /*查询本人申请*/
    @GetMapping("/selectByNum")
    public ResponseData<Object> getDailyapplyByNum(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam(value = "writedate",required = false)@DateTimeFormat(pattern = "yyyy-MM-dd")Date writedate,
            @RequestParam(value = "department",required = false) String department,
            @RequestParam(value = "reason",required = false) String reason,
            @RequestParam(value = "money",required = false) String money,
            @RequestParam(value = "rill",required = false) String rill,
            @RequestParam(value = "state",required = false) Integer state,
            @RequestParam(value = "number",required = false) String number
    ){
        return returnObject(dailyapplyService.getOnrePageUser(pageNum,pageSize, writedate, department, reason, money, rill, state, number));
    }
    /**
     * 删除日常报销申请
     */

	/*@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dailyapplyService.deleteDailyapplyByIds(ids));
    }*/
}
